home *** CD-ROM | disk | FTP | other *** search
- From: wiseman@unlv.edu (Christopher A Weiss)
- Newsgroups: comp.lang.c++
- Subject: Re: What is an algorithm? How can I use them?
- Date: 31 Jan 1996 20:32:59 GMT
- Organization: UNLV College of Engineering
- Message-ID: <4eojlr$4js@homesick.cs.unlv.edu>
- References: <310BA95F.685D@cedarnet.com>
- NNTP-Posting-Host: lil-ed.cs.unlv.edu
- X-Newsreader: TIN [version 1.2 PL2]
- Path: homesick.cs.unlv.edu!wiseman
-
- Mike Brennan (Striker@cedarnet.com) wrote:
- : What the heck is an algorithm? How might I use them? Please e-mail me.
-
- : striker@cedarnet.com
-
- An algorithm is, put simply, a way to solve a problem. Like you might
- expect, ther are good and bad ways to solve problems, therefore there
- are good and bad algorithms. How do you define an algorithm as
- "Good"? This question has several solutions - You can optimize your
- algorithms for space, time, or a balance of both. Space saving
- algorithms were very popular in the 70s/early 80s when memory was very
- expensive. Now that memory is cheap, time saving algorithms are more
- popular. Balance algorithms are usually used, but among the least
- effective. I say this because usually there is an inverse
- relationship between how fast something is and how much memory it
- uses. That is, the faster you make something go, the more memory you
- are going to use. I'm not saying this is always true, but most of the
- time it is.
-
- Now, for an example of algorithm comparison:
-
- Lets say you want to sort a group of numbers, the obvious way that
- comes to mind is called the "Bubble sort" algorithm. This algorithm
- looks at gorups of two numbers, if thy're out of order, it switches
- them. Then it looks at the next two numbers. When it reaches the
- end, it goes back to the top. It keeps doing this until it goes all
- the way thru the list without switching any. At this point, the list
- is sorted (Sorry, it's a bad explanation, but I'm trying to keep this
- short)
-
- This works, but is not considered a "good" algorithm. Why? Because
- it is, as computer scientists like to call it, an O(N^2) algorithm.
- What does this mean? That if your list has N items in it, the computer
- will have to do around (and I very loosly use the term around) N
- squared computations to sort the list. This isn't too bad at 10, 100,
- 1000, or even 100000 items. But what if you are sorting a billion
- items? Then it becomes very poor. Conversly, there are sorts like
- the heap sort or quicksort (I don't have the time to explain them)
- that solve this problem in O(nlogn) time. This is much much faster.
-
- I realize this discourse might not answer all your question, but I
- hope it helps. And to answer your question - "How do I use them in my
- programs?" Any time you write a program you use algorithms, it's just
- that you want to use good algorithms so your programs are efficent.
-
- If you are a student, search around the web for something called
- LEDA. This stands for Library of Efficient Datatypes and Algorithms.
- This is a collection of the best ways to solve problems currently
- known to computer science. If you are a student you can access them
- for free. If you are working for a company, you must pay a fee for
- them.
-
- Have fun, and write good code!
-
- --
- "Omni Ignotum Pro Magnifico" -
- Everything Unknown Passes for Something Splendid
-